//
//  GuideViewController.m
//  WXMovie
//
//  Created by apple on 16/4/8.
//  Copyright © 2016年 zic_magic. All rights reserved.
//

#import "GuideViewController.h"
#import "RootTabBarController.h"

@interface GuideViewController ()<UIScrollViewDelegate>
{
//    NSString *firstFlag;

}
@end

@implementation GuideViewController

- (void)dealloc
{
//    NSLog(@"%s", __FUNCTION__);
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self getDataFromSandBox];
//    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.size.width, self.view.size.height)];
//    imgView.image = [UIImage imageNamed:@"guide1@2x"];
//    [self.view addSubview:imgView];
    
    
//    if (![firstFlag isEqualToString: kFirstStartFlag]) {
//        [self _createView];
//    }else {
//
//        [self performSelector:@selector(changeRootViewController) withObject:nil afterDelay:1];
//    }
    
    [self _createView];
}

//- (void)changeRootViewController
//{
//    self.view.window.rootViewController = [[RootTabBarController alloc] init];
//}

- (BOOL)prefersStatusBarHidden {
    
    return  YES;
    
}


- (void)_createView {
    
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    scroll.pagingEnabled = YES;
    scroll.delegate = self;
    scroll.contentSize = CGSizeMake(5 *kScreenWidth, kScreenHeight);
    scroll.showsHorizontalScrollIndicator = NO;
    
    for (NSInteger i = 0; i < 5; i++) {
        
        NSString *imageName = [NSString stringWithFormat:@"guide%li@2x", i + 1];
        NSString *progressImageName = [NSString stringWithFormat:@"guideProgress%li@2x", i + 1];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i *kScreenWidth, 0, kScreenWidth, kScreenHeight)];
        imageView.image = [UIImage imageNamed:imageName];
        
        UIImageView *progressView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:progressImageName]];
        progressView.frame = CGRectMake(0, 0, progressView.image.size.width, progressView.image.size.height);
        progressView.center = CGPointMake(kScreenWidth / 2, kScreenHeight - 50);
        
        [imageView addSubview:progressView];
        [scroll addSubview:imageView];
        
    }
    [self.view addSubview:scroll];
    
    
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    
    if (scrollView.contentOffset.x == kScreenWidth *4) {
        
        RootTabBarController *root = [[RootTabBarController alloc] init];
        
        [UIView transitionWithView:self.view.window duration:0.5 options:
            UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            self.view.window.rootViewController = root;
        }completion:^(BOOL finished) {
//            firstFlag = kFirstStartFlag;
//            [self saveDataToSandBox];
        }];
        
    }
    
}


////保存数据到沙盒中
//- (void)saveDataToSandBox {
//    
//    if (firstFlag != nil) {
//        
//        [[NSUserDefaults standardUserDefaults] setObject:firstFlag forKey:kFirstStartFlag];
//        [[NSUserDefaults standardUserDefaults] synchronize];
//    
//    }
//}
////从沙盒中获取文件
//- (void)getDataFromSandBox {
//    
//    firstFlag = [[NSUserDefaults standardUserDefaults] objectForKey:kFirstStartFlag];
//
//    
//    [[NSUserDefaults standardUserDefaults] synchronize];
//    
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
